<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>demo</title>
</head>

<button type="button" id="sendBtn">发送</button>

<body>


  <script src="https://39.104.57.212:55555/push/socket.io/socket.io.js"></script>
  <script>

    // let uuid = window.parseInt(Math.random() * 1000000);
    // let uuid = Math.random() * 10000;
    let uuid = 'uuid002';
    let userid = 'user002';
    let socket = io.connect('https://39.104.57.212:55555/demo2?uuid=' + uuid + '&userid=' + userid, {
      path: '/push/socket.io/'
    });

    document.getElementById('sendBtn').addEventListener('click', () => {
      socket.emit('push', {
        room: 'user_user002',
        pushData: { message: 'qqqqqq' }
      }, (result) => {
        console.log(result.id);
      });
    });

    socket.on('connect', function () {
      let rooms = ['room-test'];

      socket.emit('joinRoom', rooms, function (result) {
        console.log('joinRoom:' + JSON.stringify(result));
      });

      socket.emit('info', null, function (data) {
        console.log('info' + JSON.stringify(data));
      });

      socket.emit('report-push', { id: 26 }, function (result) {
        console.log('report-push:' + JSON.stringify(result));
      })


      socket.on('push', function (data) {
        console.log('push:' + JSON.stringify(data));
        socket.emit('ackPush', { id: data.id });
      });

      socket.on('ok', function (data) {
        console.log('ok: ' + JSON.stringify(data));
      })

      socket.on('joinRoom', function (data) {
        alert('joinRoom:' + data);
      });

      socket.on('leaveRoom', function (data) {
        alert('leaveRoom:' + data);
      });

      socket.on('peopleJoin', function (data) {
        alert('peopleJoin:' + data);
      });

      socket.on('peopleLeave', function (data) {
        alert('peopleLeave:' + data);
      });

      socket.on('offlineMessage', function (msgList) {
        console.log('offlineMessage: ' + JSON.stringify(msgList));
      });


    });
  </script>
</body>

</html>